package org.example.testcode.DelayedQueue;

import java.util.Date;
import java.util.concurrent.DelayQueue;

public class Consumer implements Runnable {

    private DelayQueue<DelayedItem<String>> queue;

    public Consumer(DelayQueue<DelayedItem<String>> queue) {
        super();
        this.queue = queue;
    }

    @Override
    public void run() {
        while (true) {
            try {
                DelayedItem<String> item = queue.take();
                String data = item.getData();
                String time = System.currentTimeMillis() + ":" + new Date();
                System.out.printf("[%s] Consuming data:%s\r\n", time, data);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}